package com.gsm.projects.jobDw;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Random;

public class JobMockDataGenerator {
    private static final String URL = "jdbc:mysql://hadoop102:3306/db_job_realtime_statistics";
    private static final String USER = "root";
    private static final String PASSWORD = "123456";

    public static void main(String[] args) {
        try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD)) {
            while (true) {
                Thread.sleep(1000); // 每秒执行一次
                insertJobRecord(conn);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void insertJobRecord(Connection conn) throws Exception {
        String sql = "INSERT INTO t_job (name, city, school, type, major, graduation_date, company, position, salary, received_offer_time, entry_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
            Random random = new Random();
            // 这里简单地生成一些随机数据
            pstmt.setString(1, "Student" + random.nextInt(1000));
            pstmt.setString(2, "City" + random.nextInt(10));
            pstmt.setString(3, "School" + random.nextInt(100));
            pstmt.setString(4, "本科");
            pstmt.setString(5, "Major" + random.nextInt(50));
            pstmt.setDate(6, new java.sql.Date(System.currentTimeMillis()));
            pstmt.setString(7, "Company" + random.nextInt(1000));
            pstmt.setString(8, "Position" + random.nextInt(100));
            pstmt.setBigDecimal(9, new java.math.BigDecimal(random.nextDouble() * 100000 + 5000));
            pstmt.setTimestamp(10, new java.sql.Timestamp(System.currentTimeMillis()));
            pstmt.setTimestamp(11, new java.sql.Timestamp(System.currentTimeMillis()));
            pstmt.executeUpdate();
        }
    }
}